using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;

namespace Dogfight2008.Tests
{
  [TestFixture]
  public class TweakConfigFixture
  {
    [Test]
    public void DefaultValueHonored()
    {
      TweakConfig config = new TweakConfig();
      double value = config.GetPropertyValue("value", 5.6);
      Assert.AreEqual(5.6, value);
    }

    [Test]
    public void NoVariablesToBeginWith()
    {
      TweakConfig config = new TweakConfig();
      List<string> properties = config.GetProperties();
      CollectionAssert.IsEmpty(properties);
    }

    private List<string> List(params string[] list)
    {
      return new List<string>(list);
    }

    [Test]
    public void GetAddsAVariable()
    {
      TweakConfig config = new TweakConfig();
      config.GetPropertyValue("test", 4);
      List<string> res = config.GetProperties();
      List<string> exp = List("test");
      CollectionAssert.AreEqual(exp, res);
    }

    [Test]
    public void SecondGetDoesNotAddVariable()
    {
      TweakConfig config = new TweakConfig();
      config.GetPropertyValue("test", 4);
      config.GetPropertyValue("test", 5);
      List<string> res = config.GetProperties();
      List<string> exp = List("test");
      CollectionAssert.AreEqual(exp, res);
    }

    [Test]
    public void SecondGetDefaultValueIgnored()
    {
      TweakConfig config = new TweakConfig();
      config.GetPropertyValue("test", 5);
      double value = config.GetPropertyValue("test", 6);
      Assert.AreEqual(5, value);
    }

    [Test, ExpectedException]
    public void CannotSetNonExistentVariable()
    {
      TweakConfig config = new TweakConfig();
      config.SetPropertyValue("test", 5);
    }

    [Test]
    public void SetIsNoted()
    {
      TweakConfig config = new TweakConfig();
      config.GetPropertyValue("test", 5);
      config.SetPropertyValue("test", 6);
      Assert.AreEqual(6, config.GetPropertyValue("test", 4));
    }
  }
}
